package com.example.ormsqlsplicingframe1.filter;

import com.example.ormsqlsplicingframe1.session.SqlFilter;
import com.example.ormsqlsplicingframe1.sql.Sql;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;

@Slf4j
public class SqlLogFilter implements SqlFilter {


    @Override
    public void before(String select, Sql sql) {
        log.info(select);

        ArrayList<Object> list = new ArrayList<>(sql.getValues().size());

        for (Object o : sql.getValues()) {
            list.add(o+"("+o.getClass().getSimpleName()+")");
        }
        log.info(list.toString());
    }

    @Override
    public void before(Sql sql) {

        log.info(sql.getSql());

        ArrayList<Object> list = new ArrayList<>(sql.getValues().size());

        for (Object o : sql.getValues()) {
            list.add(o+"("+o.getClass().getSimpleName()+")");
        }
        log.info(list.toString());
    }

    @Override
    public Object after(Sql sql, Object data) {
        return data;
    }
}
